package com.lemon.blog.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import com.lemon.common.log.annotation.Log;
import com.lemon.common.log.enums.BusinessType;
import com.lemon.common.security.annotation.RequiresPermissions;
import com.lemon.blog.system.domain.BlBlogViewRecord;
import com.lemon.blog.system.service.IBlBlogViewRecordService;
import com.lemon.common.core.web.controller.BaseController;
import com.lemon.common.core.web.domain.AjaxResult;
import com.lemon.common.core.utils.poi.ExcelUtil;
import com.lemon.common.core.web.page.TableDataInfo;

/**
 * 包名称：com.lemon.blog.system.controller
 * 类名称：BlBlogViewRecordController
 * 类描述：文章浏览记录Controller
 * 创建人：@author lemon
 * 创建时间：2024-01-20
 */
@Api("文章浏览记录")
@RestController
@RequestMapping("/viewRecord")
public class BlBlogViewRecordController extends BaseController {

    @Autowired
    private IBlBlogViewRecordService blBlogViewRecordService;

    /**
     * 查询文章浏览记录列表
     * @Title: list
     * @Description: 查询文章浏览记录列表
     * @param blBlogViewRecord 文章浏览记录
     * @return: TableDataInfo
     * @throws:
     * @author: lemon
     * @Date: 2024-01-20
     */
    @RequiresPermissions("blog.system:viewRecord:list")
    @GetMapping("/list")
    public TableDataInfo list(BlBlogViewRecord blBlogViewRecord) {
        startPage();
        List<BlBlogViewRecord> list = blBlogViewRecordService.selectBlBlogViewRecordList(blBlogViewRecord);
        return getDataTable(list);
    }

    /**
     * 导出文章浏览记录列表
     * @Title: export
     * @Description: 导出文章浏览记录列表
     * @param response 客户端响应对象
     * @param blBlogViewRecord 文章浏览记录
     * @return:
     * @throws:
     * @author: lemon
     * @Date: 2024-01-20
     */
    @RequiresPermissions("blog.system:viewRecord:export")
    @Log(title = "文章浏览记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BlBlogViewRecord blBlogViewRecord) {
        List<BlBlogViewRecord> list = blBlogViewRecordService.selectBlBlogViewRecordList(blBlogViewRecord);
        ExcelUtil<BlBlogViewRecord> util = new ExcelUtil<BlBlogViewRecord>(BlBlogViewRecord.class);
        util.exportExcel(response, list, "文章浏览记录数据");
    }

    /**
     * 获取文章浏览记录详细信息
     * @Title: getInfo
     * @Description: 获取文章浏览记录详细信息
     * @param id 文章浏览记录主键
     * @return: AjaxResult
     * @throws:
     * @author: lemon
     * @Date: 2024-01-20
     */
    @RequiresPermissions("blog.system:viewRecord:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(blBlogViewRecordService.selectByPrimaryKey(id));
    }

    /**
     * 新增文章浏览记录
     * @Title: add
     * @Description: 新增文章浏览记录
     * @param blBlogViewRecord 文章浏览记录
     * @return: AjaxResult
     * @throws:
     * @author: lemon
     * @Date: 2024-01-20
     */
    @RequiresPermissions("blog.system:viewRecord:add")
    @Log(title = "文章浏览记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BlBlogViewRecord blBlogViewRecord) {
        return toAjax(blBlogViewRecordService.insert(blBlogViewRecord));
    }

    /**
     * 修改文章浏览记录
     * @Title: edit
     * @Description: 修改文章浏览记录
     * @param blBlogViewRecord 文章浏览记录
     * @return: AjaxResult
     * @throws:
     * @author: lemon
     * @Date: 2024-01-20
     */
    @RequiresPermissions("blog.system:viewRecord:edit")
    @Log(title = "文章浏览记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BlBlogViewRecord blBlogViewRecord) {
        return toAjax(blBlogViewRecordService.update(blBlogViewRecord));
    }

    /**
     * 删除文章浏览记录
     * @Title: remove
     * @Description: 删除文章浏览记录
     * @param ids 需要删除的文章浏览记录主键集合
     * @return: AjaxResult
     * @throws:
     * @author: lemon
     * @Date: 2024-01-20
     */
    @RequiresPermissions("blog.system:viewRecord:remove")
    @Log(title = "文章浏览记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(blBlogViewRecordService.deleteByBatch(ids));
    }
}
